package gis.uzd_1;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.prefs.Preferences;

import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

/**
 * Main application frame.
 * 
 * @version 0.1
 * @date 2010-04-14
 * @author Edmundas Matusevicius
 */
public class MainFrame extends JFrame {
    public MainFrame() {
        setTitle("Superb GIS Viewer");
        
        // set default/saved window position, dimensions
        
        Preferences root = Preferences.userRoot();
        final Preferences node = root.node("/gis/uzd_1");
        int left = node.getInt("left", 0);
        int top = node.getInt("top", 0);
        int width = node.getInt("width", DEFAULT_WIDTH);
        int height = node.getInt("height", DEFAULT_HEIGHT);
        setBounds(left, top, width, height);
        
        // set Windows OS look and feel
        try {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
            SwingUtilities.updateComponentTreeUI(this);
        } catch (Exception e) {
            e.printStackTrace();
        }
        
        // new window close event handling
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                // save window position, dimensions
                
                node.putInt("left", getX());
                node.putInt("top", getY());
                node.putInt("width", getWidth());
                node.putInt("height", getHeight());
                
                System.exit(0);
            }
        });
        
        // add application panel
        
        MainPanel panel = new MainPanel();
        add(panel);
    }
    
    private static final int DEFAULT_WIDTH = 800;
    private static final int DEFAULT_HEIGHT = 600;
}
